<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="项目名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作日期" prop="workDate">
        <el-date-picker
          v-model="queryParams.workDate"
          type="date"
          placeholder="选择日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item label="员工名字" prop="createUserName">
        <el-input
          v-model="queryParams.createUserName"
          placeholder="请输入员工名字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="所属角色" prop="createUserRole">
        <el-input
          v-model="queryParams.createUserRole"
          placeholder="请输入所属角色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="工作单位" prop="unitId">
        <el-select
          v-model="queryParams.unitId"
          placeholder="请选择"
          style="width: 120px"
        >
          <el-option
            v-for="item in unitlist"
            :key="item.index"
            :label="item.unitName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['item:export']"
            >导出</el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="roleList">
      <el-table-column label="ID" align="center" prop="createUserId" />
      <el-table-column
        label="项目名字"
        prop="itemName"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="员工" prop="createUserName" align="center" />
      <el-table-column label="单位名字" align="center" prop="unitName" />
      <el-table-column label="单位价格" align="center" prop="unitPrice" />
      <el-table-column label="工作量" align="center" prop="workCount" />
      <el-table-column label="工时" align="center" prop="workTime" />
      <el-table-column
        label="工作内容"
        align="center"
        prop="workContent"
        width="200"
        show-overflow-tooltip
      />
      <el-table-column
        label="工作日期"
        align="center"
        prop="workDate"
        width="120"
      />
      <el-table-column label="薪资" align="center" prop="amountSalary" />
      <el-table-column label="提成" align="center" prop="amountCommission" />
      <el-table-column label="社保" align="center" prop="amountSi" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { gzList, getWork } from "@/api/zhao/adds.js";

export default {
  name: "Role",

  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: "",
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "修改联系电话",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createUserName: "",
        createUserRole: "",
        itemName: "",
        unitId: "",
        workDate: "",
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      rules: {},
      unitlist: [],
    };
  },
  created() {
    this.getList();
    getWork().then((res) => {
      this.unitlist = res.data;
    });
  },
  methods: {
    cancel() {
      this.open = false;
    },
    getList() {
      this.loading = true;
      gzList(this.queryParams).then((res) => {
        console.log(res);
        this.roleList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "item/date/work/export",
        {
          ...this.queryParams,
        },
        `总工作列表.xlsx`
      );
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.getList();
    },
  },
};
</script>
